// request.ts
// import axios from "./axios/axios";
import axiosClass from "@/utils/axios/axiosClass";
interface IRequest {
    get: (url: string, params?: any) => void
    post: (url: string, params?: any) => void
}


class Request implements IRequest{
    static instance : Request;
    /**
     * get方法
     * @param {string} url 路径
     * @param {object} params 参数
     */
    public async get(url: string, params?: any)  {
        return new Promise((resolve, reject) => {
            axiosClass.get(url, params).then(res => {
                resolve(res);
            }).catch(err => {
                reject(err);
            })
        })
    }

    public async post(url: string, params?: any) {
        return new Promise((resolve, reject) => {
            axiosClass.post(url, params).then(res => {
                resolve(res);
            }).catch(err => {
                reject(err);
            })
        })
    }

    /**
     *
     */
    static getInstance(){
        if (!Request.instance) {
            Request.instance = new Request();
        }
        return Request.instance;
    }
}

const instance = Request.getInstance();

export default instance;
